var diag;

/**
 * 自定义公共JS方法
 */
$(function() {
	$.extend({

		'toAddDiag' : function(width, height, title, url) {
			diag = new Dialog();
			diag.Width = width;
			diag.Height = height;
			diag.Title = title;
			diag.URL = url;
			diag.show();
		},
		
		'toDetailDiag' : function(width, height, title, url) {
			diag = new Dialog();
			diag.Width = width;
			diag.Height = height;
			diag.Title = title;
			diag.URL = url;
			diag.show();
		},

		'toModDiag' : function(width, height, title, url) {
			diag = new Dialog();
			diag.Width = width;
			diag.Height = height;
			diag.Title = title;
			diag.URL = url;
			diag.show();
		}

	});
});

/**
 * 输入框
 * 得到焦点时触发事件
 */
function onFocusFun(element,elementvalue)
{
	if(element.value==elementvalue)
	{
		element.value="";
		element.style.color="#000";
	}
}
/**
 * 输入框
 * 离开输入框时触发事件
 */
function onBlurFun(element,elementvalue)
{
	if(element.value==""||element.value.replace(/s/g,"")=="")
	{
		element.value=elementvalue;
		element.style.color="#999";
	}
}

/**
 * 关闭弹出框
 */
function closePopWindow() {
	parentDialog.close();
}

/**
 * 选择所有复选框
 * @param fromName
 * @param boxname
 */
function selectAll(fromName, boxname) {
	var f = document.forms[fromName];
	for ( var i = 0; i <= f.elements.length; i++) {
		if (f.elements[i].name == boxname) {
			f.elements[i].checked = !f.elements[i].checked;
		}
	}
}

/**
 * 复选框删除功能 可以传递自定义描述
 * @param doc
 * @returns {Boolean}
 */
function confirmDel(doc) {
	var delNum = 0;
	var innerIndexs = doc.getElementsByName("innerIndexs");

	for ( var i = 0; i < innerIndexs.length; i++) {
		if (innerIndexs[i].checked) {
			delNum++;
		}
	}
	if (delNum <= 0) {
		alert("请至少选择一条待删除记录");
		return false;
	}
	var desc = "你确定要删除" + delNum + "条记录吗？\n记录删除后将无法恢复！";

	if (window.confirm(desc)) {
		document.form_del.submit();
		return true;
	} else {
		return false;
	}
}

/**
 * 页面效果公共js
 */
function MM_preloadImages() { //v3.0
	var d = document;
	if (d.images) {
		if (!d.MM_p)
			d.MM_p = new Array();
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for (i = 0; i < a.length; i++)
			if (a[i].indexOf("#") != 0) {
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
	}
}
function MM_swapImgRestore() { //v3.0
	var i, x, a = document.MM_sr;
	for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
		x.src = x.oSrc;
}
function MM_findObj(n, d) { //v4.01
	var p, i, x;
	if (!d)
		d = document;
	if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if (!(x = d[n]) && d.all)
		x = d.all[n];
	for (i = 0; !x && i < d.forms.length; i++)
		x = d.forms[i][n];
	for (i = 0; !x && d.layers && i < d.layers.length; i++)
		x = MM_findObj(n, d.layers[i].document);
	if (!x && d.getElementById)
		x = d.getElementById(n);
	return x;
}

function MM_swapImage() { //v3.0
	var i, j = 0, x, a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	for (i = 0; i < (a.length - 2); i += 3)
		if ((x = MM_findObj(a[i])) != null) {
			document.MM_sr[j++] = x;
			if (!x.oSrc)
				x.oSrc = x.src;
			x.src = a[i + 2];
		}
}
